package com.taobao.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;

/**
 * 安全配置类
 */
@EnableWebFluxSecurity
@Configuration
public class SecurityConfig {


    //安全拦截配置
    @Bean
    public SecurityWebFilterChain webFluxSecurityFilterChain(ServerHttpSecurity http) {

        return http.authorizeExchange() // 基于请求限制访问
                .pathMatchers("/**") // 拦截的请求
                .permitAll() // 允许的请求
                .anyExchange() // 其他请求
                .authenticated() // 需要认证
                .and()
                .csrf() // 防止跨站请求伪造
                .disable() // 禁用
                .build();
    }


}
